package pt.nmfa.peste.session;

import pt.nmfa.peste.entity.*;
import java.util.ArrayList;
import java.util.List;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.framework.EntityHome;

@Name("statusActionsScriptHome")
public class StatusActionsScriptHome extends EntityHome<StatusActionsScript> {

	@In(create = true)
	DeviceActionsHome deviceActionsHome;
	@In(create = true)
	StatusActionsHome statusActionsHome;

	public void setStatusActionsScriptStatusActionsScriptId(Integer id) {
		setId(id);
	}

	public Integer getStatusActionsScriptStatusActionsScriptId() {
		return (Integer) getId();
	}

	@Override
	protected StatusActionsScript createInstance() {
		StatusActionsScript statusActionsScript = new StatusActionsScript();
		return statusActionsScript;
	}

	public void load() {
		if (isIdDefined()) {
			wire();
		}
	}

	public void wire() {
		getInstance();
		DeviceActions deviceActions = deviceActionsHome.getDefinedInstance();
		if (deviceActions != null) {
			getInstance().setDeviceActions(deviceActions);
		}
		StatusActions statusActions = statusActionsHome.getDefinedInstance();
		if (statusActions != null) {
			getInstance().setStatusActions(statusActions);
		}
	}

	public boolean isWired() {
		if (getInstance().getDeviceActions() == null)
			return false;
		if (getInstance().getStatusActions() == null)
			return false;
		return true;
	}

	public StatusActionsScript getDefinedInstance() {
		return isIdDefined() ? getInstance() : null;
	}

	public List<StatusScriptParms> getStatusScriptParmses() {
		return getInstance() == null ? null : new ArrayList<StatusScriptParms>(
				getInstance().getStatusScriptParmses());
	}

}
